package com.iplant.mes.controller.sfc;

import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.annotation.trace.TraceAPI;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.serializer.CloneTool;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.mes.service.po.sfc.SFCStationEnvironment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 工位实时环境参数
 *
 * @author YouWang·Peng
 * 2024-3-25 09:50:37
 */
@RestController
@RequestMapping("/api/SFCStationEnvironment")
public class SFCStationEnvironmentController extends BasicController<SFCStationEnvironment> {
    private static final Logger logger = LoggerFactory.getLogger(SFCStationEnvironmentController.class);

    public SFCStationEnvironmentController() {
        super(SFCStationEnvironment.class);
    }

    /**
     * 新增或更新
     */
    @TraceAPI(value = "新增或更新")
    @PostMapping("/Update")
    public Object Update(HttpServletRequest request, @RequestBody Map<String, Object> wParam) {
        Object wResult;
        try {
            BMSEmployee wLoginUser = GetSession(request);
            if (!wParam.containsKey("data")) {
                return GetResult(RetCode.SERVER_CODE_ERR, RetCode.SERVER_RST_ERROR_OUT);
            }
            SFCStationEnvironment wT = CloneTool.Clone(wParam.get("data"), SFCStationEnvironment.class);

            ServiceResult<SFCStationEnvironment> wServiceResult = mPoService.UpdateSelectPo(wLoginUser, wT);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", null, wServiceResult.getResult());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode());
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }
}
